package com.kcsoft.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.kcsoft.mapper.CommandMapper;
import com.kcsoft.pojo.Command;
import com.kcsoft.pojo.PageBean;
import com.kcsoft.service.CommandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommandServiceImpl implements CommandService {

    @Autowired
    CommandMapper commandMapper;

    @Override
    public void add(String command) {
        commandMapper.add(command);
    }

    @Override
    public Command findByCommand(String command) {
        return commandMapper.findByCommand(command);
    }

    @Override
    public PageBean<Command> list(Integer pageNum, Integer pageSize) {
        PageBean<Command> pb = new PageBean<>();

        PageHelper.startPage(pageNum, pageSize);

        List<Command> al = commandMapper.list();

        Page<Command> c = (Page<Command>) al;

        pb.setItems(c.getResult());

        pb.setTotal(c.getTotal());

        return pb;
    }

    @Override
    public void delCommand(Integer id) {
        commandMapper.delCommand(id);
    }

}
